﻿//
// Created by francklinson on 2021/3/21.
//

#include "sales.h"

Sales::Sales()
= default;

Sales::Sales(const double *ar, int n)
{
    double sum{};
    for (int i = 0; i < n; ++i)
    {
        sales[i] = *ar++;
        if (sales[i] > max)
            max = sales[i];
        if (sales[i] < min)
            min = sales[i];
        sum += sales[i];
    }
    average = sum / n;
}

// 动态输入
Sales::Sales(int num)
{
    cout << "input " << num << "numbers:" << endl;
    double sum = 0;
    for (int i = 0; i < num; ++i)
    {
        cin >> sales[i];
        if (sales[i] > max)
            max = sales[i];
        if (sales[i] < min)
            min = sales[i];
        sum += sales[i];
    }
    average = sum / num;
}

void Sales::showSales() const
{
    cout << "average: " << average << endl;
    cout << "max: " << max << endl;
    cout << "min: " << min << endl;
}


